import cv2

videoCapture = cv2.VideoCapture(0)
fps = 30
size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
videoWriter = cv2.VideoWriter('my.avi',cv2.VideoWriter_fourcc('X','V','I','D'),fps,size)
success,frame = videoCapture.read()
numFramesRemaining = 10 * fps -1
while success and numFramesRemaining > 0:
    videoWriter.write(frame)
    success,frame = videoCapture.read()
    numFramesRemaining-=1
videoCapture.release()